//
//  PopularForecastViewController.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/6.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "PopularForecastViewController.h"
#import "PopularForecastFromTableViewCell.h"
#import "PopularForecastFromModel.h"
#import "PopularForecastFromModel_Two.h"

@interface PopularForecastViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    PopularForecastFromModel *_model;
    PopularForecastFromModel_Two *_forecastModel;
}
@property (nonatomic,strong) UITableView *tableView;

@end

@implementation PopularForecastViewController

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"tbg"]forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showPopularVC];
}

- (void)showPopularVC
{
    self.title = @"热门预告";
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
     
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    
    [self.view addSubview:self.tableView];
    
    self.tableView.showsHorizontalScrollIndicator = NO;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉所有cell的分割线
    
    self.tableView.tableFooterView = [[UIView alloc] init];
    
    [self getPopularForecas];
}

#pragma mark - 获取预告会议数据
- (void)getPopularForecas
{
    NSDictionary *dict = @{@"status":@"1",
                           @"page":@"1",
                           @"index":@"3"
                           };
    [KQNetWork postWithURLString:[NSString stringWithFormat:@"%@/api/meeting/index",MAIN_URL] parameters:dict success:^(NSDictionary *dic) {
        
        _model = [[PopularForecastFromModel alloc] initWithDictionary:dic];
        
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _model.list.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kHeightScale(275);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return kHeightScale(2);
}

#pragma mark - tableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseID = @"meetingthestorm";
    
    PopularForecastFromTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
    
    if (!cell)
    {
        cell = [[PopularForecastFromTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    _forecastModel = _model.list[indexPath.row];
    
    [cell setModel:_forecastModel];
    
    return cell;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (UITableView *)tableView
{
    if (!_tableView )
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, UIScreenHeight-kHeightScale(15)) style:UITableViewStylePlain];
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
    }
    return _tableView;
}

@end
